package org.elephas.webapp.model;

import org.apache.wicket.injection.web.InjectorHolder;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.elephas.model.ElephasConfiguration;
import org.elephas.service.ElephasService;

/**
 * Loads the blog application configuration from the database or creates a new
 * one with default values in case no such configuration object exists yet.
 * 
 * @author Gerolf Seitz
 * 
 */
public class DetachableElephasConfigurationModel extends
		LoadableDetachableModel<ElephasConfiguration> {

	private static final long serialVersionUID = 1L;

	@SpringBean
	private ElephasService service;

	public DetachableElephasConfigurationModel() {
		InjectorHolder.getInjector().inject(this);
	}

	@Override
	protected ElephasConfiguration load() {
		ElephasConfiguration config = service.load();
		if (config == null) {
			config = new ElephasConfiguration();
		}
		return config;
	}
}
